//
// Created by ryanc on 2018/9/25.
//

#include <jni.h>
#include <android/log.h>

#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define  LOG_TAG    "libgl2jni"
#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)

static void printGLString(const char *name, GLenum s) {
  const char *v = (const char *) glGetString(s);
  LOGI("GL %s = %s\n", name, v);
}

static void checkGlError(const char* op) {
  for (GLint error = glGetError(); error; error = glGetError()) {
    LOGI("after %s() glError (0x%x)\n", op, error);
  }
}

extern "C" JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_test(JNIEnv * env, jclass jclz, jbyteArray a, jbyteArray b)
{
  printGLString("Version", GL_VERSION);
  jbyte *arra = env->GetByteArrayElements(a, JNI_FALSE);
  jbyte *arrb = env->GetByteArrayElements(b, JNI_FALSE);
  int sizea = env->GetArrayLength(a);
  LOGI("sizea=%d", sizea);
  float fa[sizea/ sizeof(float)];
  memcpy(fa+1, arra, sizea);
  memcpy(arrb, fa, sizea);
  env->ReleaseByteArrayElements(a, arra, 0);
  env->ReleaseByteArrayElements(b, arrb, 0);
}